//
//  VillageHttpTools.m
//  Village
//
//  Created by 程虎 on 2017/9/21.
//  Copyright © 2017年 程虎. All rights reserved.
//

#import "VillageHttpTools.h"
#import "VillageDetailsModel.h"
#import "Villages.h"
#import "CodeInfo.h"

@implementation VillageHttpTools

+ (void)GetVillageInfoSuccess:(void (^)(NSArray *valueAry))success failure:(void (^)(NSString *error))failure
{
    NSMutableDictionary *bean = [NSMutableDictionary dictionary];
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [bean setValue:dict forKey:@"entitybean"];
    [dict setValue:[Globle getInstance].account.areaid.length > 0 ? [Globle getInstance].account.areaid : ([Globle getInstance].areaid.length > 0 ? [Globle getInstance].areaid : @"") forKey:@"areaid"];
    [NetRequestClass Post:getOrgInfoURL Parameters:bean success:^(id result) {
        if (success) {
            NSDictionary *dict = result[@"data"];
            success([VillageHttpTools configDict:dict]);
        }
    } failure:^(id valueCode, id error) {
        if (failure) {
            failure(error);
        }
    }];
}

+ (NSMutableArray *)configDict:(NSDictionary *)dict
{
    VillageDetailsModel *model = [VillageDetailsModel mj_objectWithKeyValues:dict];
    
    NSDictionary *dict1 = @{@"icon":@"default_img",@"codetype":@"金融港村委"};
    
    NSMutableArray *data1 = [NSMutableArray arrayWithObjects:
                             @{@"titles":@"统一社会信用代码",@"contents":model.orginfo.unicode},
                             @{@"titles":@"街道",@"contents":model.orginfo.orgname},
                             @{@"titles":@"机构类型",@"contents":model.orginfo.orgtypecn},
                             @{@"titles":@"详细地址",@"contents":model.orginfo.location},
                             @{@"titles":@"有效期限(始)",@"contents":model.orginfo.orgstartdate},
                             @{@"titles":@"有效期限(止)",@"contents":model.orginfo.orgdeadline},
                             @{@"titles":@"核准时间",@"contents":model.orginfo.checktime},
                             @{@"titles":@"联系人",@"contents":model.orginfo.contact},
                             @{@"titles":@"联系电话",@"contents":model.orginfo.contactnumber}, nil];
    if (model.orginfo.orgcode.length) {
        NSDictionary *dicts = @{@"titles":@"原组织结构代码",@"contents":model.orginfo.orgcode};
        [data1 insertObject:dicts atIndex:4];
    }
    
    NSArray *data2 = @[@{@"titles":@"法定代表人",@"contents":model.legalinfo.legalperson},
                       @{@"titles":@"法人身份证号",@"contents":model.legalinfo.legalpersonno},
                       @{@"titles":@"民族",@"contents":model.legalinfo.nationcn},
                       @{@"titles":@"党员",@"contents":model.legalinfo.ispartyercn},
                       @{@"titles":@"学历",@"contents":model.legalinfo.educationcn},
                       @{@"titles":@"兼任党委组织书记",@"contents":model.legalinfo.issecretariescn}];
    NSArray *data3 = @[@{@"titles":@"村民(居民)小组数",@"contents":model.other.groupnum},
                       @{@"titles":@"户数",@"contents":model.other.villagenum},
                       @{@"titles":@"自然村数",@"contents":model.other.registernum}];
    NSMutableArray *valueAry = [NSMutableArray arrayWithObjects:[CodeInfo mj_objectWithKeyValues:dict1],[Villages mj_objectArrayWithKeyValuesArray:data1],[Villages mj_objectArrayWithKeyValuesArray:data2],model.persons,[Villages mj_objectArrayWithKeyValuesArray:data3], nil];
    
    return valueAry;
}
@end
